﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<script>
    $(function () {
        gridList();
    })
   function gridList() {
        var template1 =
        {
            "groupOp": "AND",
            "rules": [
            { "field": "username", "op": "bw", "data": "Athena" },
            { "field": "rolelist", "op": "gt", "data": "管理员" }
            ]
        };
        var template2 =
        {
            "groupOp": "AND",
            "rules": [
              { "field": "rolelist", "op": "eq", "data": "黄金会员" },
              { "field": "username", "op": "le", "data": "Athena" }
            ]
        };

        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/SystemManage/User/GetGridJson",
            height: $(window).height() - 128,
            colModel: [
                { label: '主键', name: 'id', hidden: true },
                { label: '用户名', name: 'username', width: 150, align: 'left' },
                //{ label: '密码', name: 'password', width: 150, align: 'left' },
                { label: '角色', name: 'rolelist', width: 200, align: 'left' },
                {
                    label: '分组', name: 'grouplist', width: 200, align: 'left'
                }
            ],
            //pager: "#gridPager",
            pager: '#pgrps3',
            sortname: 'id asc',
            viewrecords: true
        });
        jQuery("#gridList").jqGrid('navGrid', '#pgrps3',
        { edit: false, add: false, del: false },
        {},
        {},
        {},
        {
            multipleSearch: true,
            multipleGroup: true,
            showQuery: true,
            // set the names of the template
            "tmplNames": ["模板一", "模板二"],
            // set the template contents
            "tmplFilters": [template1, template2]
        }
        );


        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增用户",
            url: "/SystemManage/User/Form",
            width: "800px",
            height: "600px",
            btn: null,
            shade:"0",
        
        });
    }
    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().id;
        $.modalOpen({
            id: "Form",
            title: "修改用户",
            url: "/SystemManage/User/Form?keyValue=" + keyValue,
            width: "800px",
            height: "600px",
            btn: null,
            shade:"0",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_delete() {
        $.deleteForm({
            url: "/SystemManage/User/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().id },
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_details() {
        var keyValue = $("#gridList").jqGridRowValue().id;
        var pubkey = $("#gridList").jqGridRowValue().pubkey;
        var prikey = $("#gridList").jqGridRowValue().prikey;
        $.modalOpen({
            id: "Details",
            title: "查看用户",
            url: "/SystemManage/User/Details?keyValue=" + keyValue + '&pubkey=' + escape(pubkey) + '&prikey= ' + escape(prikey),
            width: "700px",
            height: "550px",
            btn: null,
        });
    }
    function btn_CopyAndPaste() {
        var keyValue = $("#gridList").jqGridRowValue().id;
        $.copyAndPasteForm({
            url: '/SystemManage/User/copyAndPasteForm',
            param:{keyValue:keyValue},
            success: function () {
               $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
       })
    }

    function btn_OpenRevisePasswordDialog() {
        var keyValue = $("#gridList").jqGridRowValue().id;
        var RealName = $("#gridList").jqGridRowValue().username;
        //var password = $("#gridList").jqGridRowValue().password;
        $.modalOpen({
            id: "RevisePassword",
            title: '重置密码',
            url: '/SystemManage/User/RevisePassword?keyValue=' + keyValue + '&realName=' + escape(RealName),
            width: "450px",
            height: "300px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            },
        });
       
  }
  
    

</script>

<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a id="NF-add" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新建用户</a>
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
                <li><a id="NF-edit" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改用户</a></li>
                <li><a id="NF-delete" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除用户</a></li>
                <li><a id="NF-Details" onclick="btn_details()"><i class="fa fa-search-plus"></i>查看用户</a></li>
            @*    <li><a id="NF-CopyAndPaste" onclick="btn_CopyAndPaste()"><i class="fa fa-search-plus"></i>复制粘贴</a></li>*@
                <li class="split"></li>
                <li><a id="NF-revisepassword" authorize="yes" onclick="btn_OpenRevisePasswordDialog()"><i class="fa fa-key"></i>密码重置</a></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
     </div>
    <div class="search">
        <table>
            <tr>
                <td style="padding-right:3px;">
                    <div class="btn-group">
                        <a class="btn btn-primary dropdown-text" onclick="advance_search()">高级查询</a>
                    </div>
                </td>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="姓名" style="width: 200px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>

<table id="grps3"></table>
<div id="pgrps3"></div>


